class MatchFunctionNode extends MyNode{
    constructor($state='new',...obj){
        super('MatchFunction',$state,{
            name:"函数名",
            body: `
function (a,params){
    return false;
}`
        },...obj);
    }

    static loadFunctions(){
        let session = neo4jService.getSession();
        let resultPromise = session.run(`MATCH (n:MatchFunction) RETURN n`);
        resultPromise.then(result => {
            session.close();
            MatchFunctionNode.functions = result.records
                .map((record) => record.get(0))
                .map(node => MyNode.fromNeo4jNode(node));
            for (let fn of MatchFunctionNode.loadFunctions.callbacks){
                fn(MatchFunctionNode.functions);
            }
        });
    }
}
MatchFunctionNode.functions=[];
// MatchFunctionNode.loadFunctions();
MatchFunctionNode.loadFunctions.callbacks=[];

const matchFactory = function (opertion) {
    switch (opertion){
        case '>':
            return (a,params)=>Number(a) > Number(params[0]);
        case '<':
            return (a,params)=>Number(a) < Number(params[0]);
        case '>=':
            return (a,params)=>Number(a) >= Number(params[0]);
        case '<=':
            return (a,params)=>Number(a) <= Number(params[0]);
        case '=':
            return (a,params)=>a == params[0];
        case 'between':
            return (a,params)=>Number(a) >= Number(params[0]) && Number(a) <= Number(params[1]);
        case 'in':
            return (a,params)=>{
                for (let param of params){
                    if(param==a){
                        return true;
                    }
                }
                return false;
            };
        default:
    }

    for (let func of MatchFunctionNode.functions){
        if(func.name==opertion){
            return eval(`(${func.body})`);
        }
    }
    return (a,params)=>false;
};